home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------
- # MultiFinder-Aware Simple NoDraft Application
- #
- # Dialogs.c - Dialog handling code
- #
- -------------------------------------------- */
-
- #include <Values.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Desk.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <SegLoad.h>
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Packages.h>
- #include <Controls.h>
- #include <Printing.h>
- #include <Traps.h>
- #include <NoDraft.h>
- #include <Nodraft_types.h>
-
- pascal TPPrDlg MyJobDlgInit();
-
- THPrint hPrintRec;
-
- /*-------------------------------------------- */
-
- void FlashDialogItem(the_dialog, theItem)
-
- DialogPtr the_dialog;
- short theItem;
-
- {
- short itemType;
- Rect itemRect;
- Handle itemHdl;
- long longdelay, longticks;
-
- GetDItem(the_dialog, theItem, &itemType, &itemHdl, &itemRect);
-
- if ( itemHdl != nil) {
- HiliteControl( (ControlHandle) itemHdl, 1);
- longdelay = longticks = 6;
- Delay(longdelay, &longticks);
- }
- }
-
- /*-------------------------------------------- */
-
- void checknetwork()
-
- {
- static int count = 0;
- /* I use this routine to check for AppleTalk™
- messages rather than include all that code,
- I just beep every once in a while to let
- you know it is working, you can change
- delay_length to increase/decrease
- freq of Beeps */
- if ( count++ > delay_length ) {
- SysBeep(3);
- count = 0;
- }
- } /* end of checking the network */
-
- /*-------------------------------------------- */
-
- pascal Boolean Net_filter(theDialog, theEvent, itemHit)
-
- DialogPtr theDialog;
- EventRecord *theEvent;
- short *itemHit;
-
- {
-
- int key;
- Boolean handled_event;
-
- handled_event = false; /* did we handle the event */
-
- /* do whatever you have to do for event */
-
- switch ( theEvent->what) {
-
- case nullEvent:
- checknetwork();
- break;
-
- case keyDown:
- key = theEvent->message & charCodeMask;
- if (( key == cr) || ( key == enter))
- {
- FlashDialogItem(theDialog, ok);
- *itemHit = ok;
- handled_event = true; /* handled it */
- }
- break;
-
- /* we get all kinds of update events here some for our modal dialog and even some
- for the different windows ( in some cases)
- rather than try and process these so that
- we do get real null events when
- we can check the network, just check the
- network and let the update events get
- processed later */
-
- checknetwork();
- break;
-
- case activateEvt:
- break;
-
- default:
- /* Don't know what we got here, but */
- /* but check the network in case we */
- /* get stuck on this event like we */
- /* did with updates */
-
- checknetwork();
- break;
- }
-
- /* return boolean to tell modal dialog to */
- /* handle the event or not */
-
- return (handled_event);
- }
-
- /*-------------------------------------------- */
-
- void ShowAboutMeDialog(void) /* my about… dialog */
-
- {
- short itemHit;
-
- itemHit = Alert(rAboutAlert, &Net_filter);
-
- } /* ShowAboutMeDialog */
-
- /*-------------------------------------------- */
-
- void DisableDraftMode(thePrintDialog)
-
- TPPrDlg thePrintDialog;
-
- /* disable the ability to print out draft */
- /* mode since we can't print our bitmaps */
-
- {
- DialogPeek theDialogPtr;
- short i;
- short num_items; /* how many in list */
-
- hItemList hItems; /* Handle to DLOG’s list */
-
- short item_no;
- short draft_item_no;
- short better_item_no;
- short best_item_no;
- short the_type; /* vars from GetDitem */
- Handle the_item;
- Rect the_box;
-
- char *the_title = " ";
-
- short the_and_type;
-
- char *draft_title, *better_title;
- char *best_title;
-
- Boolean draft_selected;
- short draft_value;
-
- /* we are given a DialogPtr which is a ptr */
- /* to the print dialog */
- /* scan through all the items, and if you */
- /* get one called draft, disable it */
-
- /* how many items are there to scan */
-
- theDialogPtr = (DialogPeek)thePrintDialog;
-
- hItems = (hItemList) (theDialogPtr->items);
- num_items = (*hItems)->dlgMaxIndex + 1;
-
- draft_title = "Draft";
- better_title = "Faster";
- best_title = "Best";
- draft_selected = false;
-
- for (i = 1; i <= num_items; i++ )
- {
- /* get the item */
-
- item_no = i;
-
- GetDItem( (DialogPtr) theDialogPtr, item_no, &the_type, &the_item, &the_box);
-
- /* used to bit and with 7F */
- the_and_type = the_type & 0X7F;
- switch ( the_and_type ) {
- /* is it a radio button */
- case ctrlItem + radCtrl:
- getctitle( (ControlHandle) the_item, the_title);
- if ((*the_title) == (*draft_title))
- {
- draft_value = GetCtlValue((ControlHandle) the_item);
- if ( draft_value > 0 )
- {
- draft_selected = true;
- draft_value = 0;
- SetCtlValue((ControlHandle) the_item, draft_value);
- }
- HiliteControl( (ControlHandle) the_item, 255);
- /* comment the previous line and uncomment */
- /* the next two lines of code to see the */
- /* difference between disabling item */
- /* and inactivating control */
-
- /* the_and_type = the_type | 0X80; */
- /* SetDItem( (DialogPtr) theDialogPtr, item_no, the_and_type, the_item, &the_box); */
- draft_item_no = item_no;
- }
- else
- if ((*the_title) == (*better_title) )
- better_item_no = item_no;
- else
- if ((*the_title) == (*best_title) )
- best_item_no = item_no;
-
- break;
- } /* end of switch */
-
- } /* of for loop */
-
- } /* of disabling the printing in draft mode */
-
- /*-------------------------------------------- */
-
- pascal TPPrDlg MyJobDlgInit(hPrint)
-
- THPrint hPrint;
-
- {
- /* call PrJobInit to get pointer to the */
- /* invisible job dialog */
- PrtJobDialog = PrJobInit(hPrint);
- if (PrError() != noErr)
- return nil;
-
- /* set up the filter function */
- PrtJobDialog->pFltrProc = (ModalFilterProcPtr)&Net_filter;
-
- /* disable the draft mod now */
-
- DisableDraftMode(PrtJobDialog);
-
- /* PrDlgMain expects pointer the modified */
- /* dialog to be returned.... */
-
- return ( PrtJobDialog );
-
- } /* myJobDlgInit */
-
- /*--------------------------------------------*/
-
- OSErr DoPrintDialog()
-
- {
- hPrintRec = (THPrint) NewHandle(sizeof(TPrint));
- PrintDefault(hPrintRec);
- PrValidate(hPrintRec);
- if (PrError() != noErr)
- return PrError();
-
- /* Here’s the line that does it all! */
- if (!PrDlgMain(hPrintRec,&MyJobDlgInit))
- return 2;
-
- if (PrError() != noErr)
- return PrError();
-
- /* that’s all for now */
- }
-